package com.ld.admin.service.system.dbbackup.queue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import com.ld.shieldsb.common.core.queue.QueueEntry;

public class DBbackUpRunningQueue<T> {

    private BlockingQueue<QueueEntry<T>> queue;

    public DBbackUpRunningQueue() {
        this(10000);
    }

    protected DBbackUpRunningQueue(int queueSize) {
        queue = new LinkedBlockingQueue<QueueEntry<T>>(queueSize);
    }

    public void put(String key, T model) {
        try {
            queue.put(new QueueEntry<T>(key, model));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public T get() {
        QueueEntry<T> entity = queue.poll();
        if (entity == null) {
            return null;
        }
        return entity.getModel();
    }

}